package org.zmhhxl.user.domain.repository;

import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.zmhhxl.api.auth.domain.entity.ThirdPartyUser;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;

public interface ThirdPartyUserRepository extends JpaRepository<ThirdPartyUser, Long> {

   @EntityGraph(attributePaths = {"userInfos"})
   Optional<ThirdPartyUser> findById(Long id);

   /**
    * 根据第三方id和类型查询第三方用户
    * */
   ThirdPartyUser findByThirdPartyIdAndThirdPartyType(String thirdPartyId, String thirdPartyType);

   Set<ThirdPartyUser> findAllByThirdPartyIdIn(Collection<String> id);

   Set<ThirdPartyUser> findAllByIdIn(List<Long> id);

   @EntityGraph(attributePaths = {"userInfos"})
   Optional<ThirdPartyUser> findByThirdPartyIdAndThirdPartyDomain(String thirdPartyId, String thirdPartyDomain);

   void deleteById(Long id);

   ThirdPartyUser save(ThirdPartyUser thirdPartyUser);

}
